﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
    <link href="/lib/jquery/jquery-ui.min.css" rel="stylesheet" />
    <script src="/lib/jquery/jquery-ui.min.js"></script>
</head>
<body>
    <div class="data-wrap case">
        <div class="data-tool clearfix">
            <div class="pull-left form-inline ">
                <a class="btn btn-default btn-sm" data-href="/view/role/add.html" data-title="新增" data-width="452" data-height="465" onclick="return edit(this)"><span class="glyphicon glyphicon-plus"></span> 新增</a>
            </div>
            <div class="pull-right">
                <form class="form-inline" id="formSearch">
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon">公司名称：</label>
                        <input class="form-control" name="companyName" type="text">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon">角色名称：</label>
                        <input class="form-control" name="rName" type="text">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon">状态：</label>
                        <select class="form-control" name="rStatus">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="2">禁用</option>
                        </select>

                    </div>
                    <button type="button" class="btn btn-default btn-sm active" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </form>
            </div>
        </div>
        <div class="paging">
        </div>
    </div>
    <script type="text/x-dot-template" id="rolePagerTemplate">
        <div class="data-body data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table table-hover table-striped table-bordered">
                        <thead>
                            <tr>
                                <th width="250" class="t_l">角色名称</th>
                                <th class="t_l">公司名称</th>
                                <th width="100">状态</th>
                                <th width="270">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {{? it.tData && it.tData.length>0}}
                            {{~it.tData :item:index}}
                            <tr>
                                <td width="250" class="t_l">{{= item.rName }}</td>
                                <td class="t_l">{{= item.companyName }}</td>
                                <td width="100">
                                    {{? item.rStatus==1 }}
                                    <span class="green bold">启用</span>
                                    {{?? }}
                                    <span class="red bold">禁用</span>
                                    {{? }}
                                </td>
                                <td width="270">
                                    {{? item.rStatus==1 }}
                                    <a class="btn btn-warning btn-xs" data-confirm=' "{{= item.rName }}" <br>确定要<span class="orange">禁用</span>该角色？' data-href="/Role/UpdateStatus?id={{= item.rId}}&status=2">禁用</a>
                                    {{?? }}
                                    <a class="btn btn-success btn-xs" data-confirm=' "{{= item.rName }}" <br>确定要<span class="green">启用</span>该角色？' data-href="/Role/UpdateStatus?id={{= item.rId}}&status=1">启用</a>
                                    {{? }}
                                    <button type="button" class="btn btn-default btn-xs" data-href="/view/role/edit.html?id={{= item.rId}}" data-title="编辑 - {{= item.rName }}" data-width="452" data-height="465" onclick="return edit(this)">
                                        <span class="glyphicon glyphicon-edit"></span> 编辑
                                    </button>
                                    <button type="button" class="btn btn-default btn-xs" data-href="/view/role/clone.html?id={{= item.rId}}" data-title="复制 - {{= item.rName }}" data-width="452" data-height="465" onclick="return edit(this)">
                                        <span class="glyphicon glyphicon-edit"></span> 复制
                                    </button>
                                    <a class="btn btn-danger btn-xs" data-confirm='"{{= item.rName }}" <br>确定要<span class="red">删除</span>该角色？' data-href="/Role/Delete?id={{= item.rId}}"><span class="glyphicon glyphicon-trash"></span> 刪除</a>
                                </td>
                            </tr>
                            {{~}}
                            {{??}}
                            <tr class="noRecord">
                                <td colspan="4">暂无记录！</td>
                            </tr>
                            {{?}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- 必要的分页参数设置 -->
        <input type="hidden" id="TotalCount" value="{{=it.totalCount}}" />
    </script>
    <script type="text/javascript">
        //菜单状态
        var menuStatus ={
            show: 1,
            hide: 2
        };

        $(function () {
            FlashPay.UI.DataAutoHeight();

            FlashPay.UI.DoSearch();


            $("#btnSearch").click(function () {
                window.currentPage = null;
                doSearch();
            });
        });



        $(document).keyup(function (event) {
            var keycode = event.which;
            if (keycode == 13) {
                FlashPay.UI.DoSearch();
            }
        }); 

        $("input[name='companyName']").autocomplete({
            minLength:1,
            source: function (request, response) {
                FlashPay.Util.Ajax({
                    url: '/Role/CompanySearch',
                    type: 'POST',
                    data: { companyName: $("input[name='companyName']").val() },
                    success: function (res) {
                        if (res.success) {
                            if (res.data != null && res.data.length > 0) {
                                response($.map(res.data, function (item) {
                                    return {
                                        label: item.companyName,
                                        value: item.companyName,
                                        id: item.companyID
                                    }
                                }))
                            }
                        } else {
                            FlashPay.UI.Tip_warning("操作失败！" + res.errorMessage);
                        }
                    },
                    error: function (json) {
                        FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                    }
                });
            }
        });

        $("input[name='rName']").autocomplete({
            minLength: 1,
            source: function (request, response) {
                FlashPay.Util.Ajax({
                    url: '/Role/RoleAutoSearch',
                    type: 'POST',
                    data: { RName: $("input[name='rName']").val() },
                    success: function (res) {
                        if (res.success) {
                            if (res.data != null && res.data.length > 0) {
                                response($.map(res.data, function (item) {
                                    return {
                                        label: item.rName,
                                        value: item.rName,
                                        id: item.rId
                                    }
                                }))
                            }
                        } else {
                            FlashPay.UI.Tip_warning("操作失败！" + res.errorMessage);
                        }
                    },
                    error: function (json) {
                        FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                    }
                });
            }
        });

        function edit(obj) {

            var that = $(obj);

            FlashPay.UI.DialogOpen(that.data("href"), {
                title: that.data("title"),
                width: that.data("width"),
                height: that.data("height")
            });
        }

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function doSearch() {
            FlashPay.UI.Pager(".paging", { templateId: "rolePagerTemplate", pageSize: 15, ajax: { url: '/Role/GetPager' } });
        }

    </script>
</body>
</html>